class Solution {
    public int GetHeight(TreeNode root){
        if(root == null){
            return 0;
        }
        int leftHeight = GetHeight(root.left);
        int rightHeight = GetHeight(root.right);
        if(leftHeight>=0&&rightHeight>=0&&Math.abs(rightHeight - leftHeight) <= 1)
            return Math.max(leftHeight,rightHeight)+1;
        else{
            return -1;
        }
    }
    public boolean isBalanced(TreeNode root) {
        // 空树是平衡二叉树
        if(root == null){
            return true;
        }
        return GetHeight(root)>=0;
    }
}